Advertisement
nshelper

WP GlobalCart - klarna-checkout-for-woocommerce

May 20th, 2024
565
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.80 KB | None | 0 0
  1.     public function process_cart() {
  2.         foreach ( WC()->cart->get_cart() as $cart_item ) {
  3.             do_action( 'woocommerce/cart_loop/start', $cart_item );
  4.             if ( $cart_item['quantity'] ) {
  5.                 if ( $cart_item['variation_id'] ) {
  6.                     $product = wc_get_product( $cart_item['variation_id'] );
  7.                 } else {
  8.                     $product = wc_get_product( $cart_item['product_id'] );
  9.                 }
  10.                 $this->total_amount        = self::format_number( $cart_item['line_total'] );
  11.                 $this->subtotal_amount     = self::format_number( $cart_item['line_subtotal'] );
  12.                 $this->total_tax_amount    = self::format_number( array_sum( $cart_item['line_tax_data']['total'] ) );
  13.                 $this->subtotal_tax_amount = self::format_number( array_sum( $cart_item['line_tax_data']['subtotal'] ) );
  14.                 $this->quantity            = $cart_item['quantity'];
  15.  
  16.                 $klarna_item = array(
  17.                     'reference'             => $this->get_item_reference( $product ),
  18.                     'name'                  => $this->get_item_name( $cart_item ),
  19.                     'quantity'              => $this->get_item_quantity( $cart_item ),
  20.                     'unit_price'            => $this->get_item_price( $cart_item ),
  21.                     'tax_rate'              => $this->get_item_tax_rate( $cart_item, $product ),
  22.                     'total_amount'          => $this->get_item_total_amount( $cart_item, $product ),
  23.                     'total_tax_amount'      => $this->get_item_tax_amount( $cart_item, $product ),
  24.                     'total_discount_amount' => $this->get_item_discount_amount( $cart_item, $product ),
  25.                 );
  26.  
  27.                 if ( class_exists( 'WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) {
  28.                     $klarna_item['subscription'] = array(
  29.                         'name'           => $klarna_item['name'],
  30.                         'interval'       => strtoupper( WC_Subscriptions_Product::get_period( $product ) ),
  31.                         'interval_count' => absint( WC_Subscriptions_Product::get_interval( $product ) ),
  32.                     );
  33.                 }
  34.  
  35.                 // Product type.
  36.                 if ( $product->is_downloadable() || $product->is_virtual() ) {
  37.                     $klarna_item['type'] = 'digital';
  38.                 } else {
  39.                     $klarna_item['type'] = 'physical';
  40.                 }
  41.  
  42.                 // Add images.
  43.                 $klarna_checkout_settings = get_option( 'woocommerce_kco_settings', array() );
  44.                 if ( isset( $klarna_checkout_settings ) && 'yes' === $klarna_checkout_settings['send_product_urls'] ) {
  45.                     $klarna_item['product_url'] = $this->get_item_product_url( $product );
  46.                     if ( $this->get_item_image_url( $product ) ) {
  47.                         $klarna_item['image_url'] = $this->get_item_image_url( $product );
  48.                     }
  49.                 }
  50.  
  51.                 /* This should better support get_catalog_visibility = hidden on product components.  */
  52.                 $cart_line_item = apply_filters( 'kco_wc_cart_line_item', $klarna_item, $cart_item );
  53.                 if ( $cart_line_item ) {
  54.                     $this->order_lines[] = $cart_line_item;
  55.                 }
  56.             }
  57.             do_action( 'woocommerce/cart_loop/end', $item );
  58.         }
  59.     }
Advertisement
Comments
  • nshelper
    13 days
    # text 0.10 KB | 0 0
    1. /wp-content/plugins/klarna-checkout-for-woocommerce/classes/requests/helpers/class-kco-request-cart.php
  • nshelper
    13 days
    Comment was deleted
Add Comment
Please, Sign In to add comment
Advertisement